package com.example.expandablelistview.menu;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Button;

import com.example.expandablelistview.R;

public class MenuCheck extends Activity {
	Button mBtn;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menucheck);
		mBtn = (Button) findViewById(R.id.menucheck_btn);
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater infalter = getMenuInflater();
		infalter.inflate(R.menu.menucheck, menu);
		return true;
	}

	public boolean onPrepareOptionsMenu(Menu menu) {
		super.onPrepareOptionsMenu(menu);
		if (mBtn.getTextSize() == 40) {
			menu.findItem(R.id.bigfont).setChecked(true);
		} else {
			menu.findItem(R.id.bigfont).setChecked(false);
		}
		int color = mBtn.getTextColors().getDefaultColor();

		if (color == Color.RED) menu.findItem(R.id.red).setChecked(true);
		if (color == Color.GREEN) menu.findItem(R.id.green).setChecked(true);
		if (color == Color.BLUE) menu.findItem(R.id.blue).setChecked(true);
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
			case R.id.bigfont:
				if (item.isChecked()) mBtn.setTextSize(
						TypedValue.COMPLEX_UNIT_PX, 20);
				else mBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, 40);
				return true;
			case R.id.red:
				mBtn.setTextColor(Color.RED);
				break;
			case R.id.green:
				mBtn.setTextColor(Color.GREEN);
				break;
			case R.id.blue:
				mBtn.setTextColor(Color.BLUE);
				break;
		}
		return false;
	}

}
